﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Text;

namespace Catering
{
    public partial class TestPage : System.Web.UI.Page
    {
       
        Catering_Rules.T_RawMaterials crrm = new Catering_Rules.T_RawMaterials();
        Catering_Rules.DishType crdt = new Catering_Rules.DishType();
       
        protected void Page_Load(object sender, EventArgs e)
        {
           
            if (!IsPostBack)
            {
                new View_Operaction_Common().RepeaterDataBind(GetDatatable(),Repeater1,Request,10,lblCurPage,InkPrev,InkLast,InkFirst,InkNext);
            }
        }
        private DataTable GetDatatable(string strWhere=null)
        {
             Catering_Rules.ViewOperaction vop = new Catering_Rules.ViewOperaction();
            DataSet ds = new DataSet();
            if (strWhere!=null)
            {
               ds= vop.GetViewToDataSet("Purchase_user", strWhere);
            }
            else
            {
               ds= vop.GetViewToDataSet("Purchase_user");
            }
            StringBuilder sb = new StringBuilder();
           
            if (ds != null && ds.Tables.Count > 0)
            {
                return ds.Tables[0];
            }
            else
            {
                return null;
            }
        }
        private void RepeaterDataBind(DataTable dt)
        {
            PagedDataSource objPage = new PagedDataSource();
            //设置数据源 DefaultView：获取可能包含筛选视图或游标位置表的自定义视图
            objPage.DataSource = dt.DefaultView;
            //允许分页
            objPage.AllowPaging = true;
            //设置每页个数
            objPage.PageSize = 12;
            //定义变量保存当前页的索引值

            int CurPage;
            //判断是否具有页面跳转的请求
            if (Request.QueryString["Page"] != null)
            {
                CurPage = Convert.ToInt32(Request.QueryString["Page"]);
            }
            else
            {
                CurPage = 1;
            }
            //设置当前页的索引
            objPage.CurrentPageIndex = CurPage - 1;
            //显示状态信息
            lblCurPage.Text = "第" + CurPage.ToString() + "/" + objPage.PageCount + "页";
            //如果当前页面不是首页
            if (!objPage.IsFirstPage)
            {
                //定义“上一页”超级链接的URL为：当前执行页面的虚拟路径，并传递下一页面的索引值 
                InkPrev.NavigateUrl = Request.CurrentExecutionFilePath + "?Page=" + Convert.ToString(CurPage - 1);

            }
            InkLast.NavigateUrl = Request.CurrentExecutionFilePath + "?Page=" + (objPage.PageCount);
            InkFirst.NavigateUrl = Request.CurrentExecutionFilePath + "?Page=1";
           
            //如果当前页面不是最后一页
            if (!objPage.IsLastPage)
            {
                //定义“下一页”超级链接的URL为：当前执行页面的虚拟路径，并传递下一页面的索引值 
                InkNext.NavigateUrl = Request.CurrentExecutionFilePath + "?Page=" + Convert.ToString(CurPage + 1);
            }
            //将PagedDataSource作为数据源
            Repeater1.DataSource = objPage;

            //进行数据绑定
            Repeater1.DataBind();
        }
       
    }
}